home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Extension Shell 1.5 (Source) / Extension Shell 1.5 Includes / THINKA4.h < prev   
Text File  |  1996-04-12  |  2KB  |  79 lines

  1. /*    NAME:
  2.         THINKA4.h
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant, based on Eric Shapiro's code for his July 1993 BYTE article.
  6.         
  7.     DESCRIPTION:
  8.         To use as replacements for the Metrowerks A4 setup/restore routines,
  9.         you should replace code which looks like:
  10.         
  11.                 {    long oldA4;
  12.                 ...
  13.                 oldA4 = SetCurrentA4();
  14.                 ...
  15.                 SetA4(oldA4);
  16.                 }
  17.         
  18.         
  19.         with code which looks like:
  20.         
  21.                 {
  22.                 ...
  23.                 GetGlobals();
  24.                 ...
  25.                 UngetGlobals();
  26.                 }
  27.         
  28.         You will also need to #include this file.
  29.  
  30.     ___________________________________________________________________________
  31. */
  32. #ifndef __THINK_A4__
  33. #define __THINK_A4__
  34. //=============================================================================
  35. //        Defines
  36. //-----------------------------------------------------------------------------
  37. // To be called from main() in an INIT resource that wants to lock itself in
  38. // memory and stay around after its resource file is closed.
  39. #define    LockSelf()            asm {                                                    \
  40.                                 lea            main, A0        ; &main into A0            \
  41.                                 dc.w        _RecoverHandle    ; get handle to self    \
  42.                                 move.l        A0, -(SP)        ; save handle to self    \
  43.                                 dc.w        _HLock            ; lock self             \
  44.                                 dc.w        _DetachResource    ; detach from rez fork    \
  45.                                 }
  46.  
  47.  
  48. // Saves the current value of A4 on the stack, and puts a copy of the address of main
  49. // into A4. Should be called at start of stand-alone code resource to access globals.
  50. #define GetGlobals()        asm {                                                     \
  51.                                 move.l         A4, -(SP)        ; save old A4            \
  52.                                 lea         main, A4         ; get globals            \
  53.                                 }
  54.  
  55.  
  56. // The converse of GetGlobals(). Restore the value of A4                        
  57. #define UngetGlobals()        asm {                                                    \
  58.                                 move.l         (SP)+, A4        ; restore A4 from stack    \
  59.                                 }
  60.  
  61.  
  62. // Save some registers, and retrieve access to our globals via A4. Remove your
  63. // paramaters from the stack into local registers before PatchGetGlobals()
  64. #define PatchGetGlobals()    asm {                                                     \
  65.                                 movem.l     A0-A5/D0-D7, -(SP)    ; save registers    \
  66.                                 lea         main, A4             ; get globals        \
  67.                                 }
  68.  
  69.  
  70. // The converse of PatchGetGlobals. If your return value is held in a global,
  71. // make sure you copy it into a local variable before calling this macro - when
  72. // A4 has been restored, your globals are now longer accessible.
  73. #define PatchUngetGlobals()    asm {                                                    \
  74.                                 movem.l     (SP)+, A0-A5/D0-D7    ; restore registers    \
  75.                                 }
  76.  
  77.  
  78. #endif
  79.